﻿using System.Reflection;
using K9Nano.Updater.Pipes;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;

namespace K9Nano.Updater;

public static class K9UpdateStartupExtension
{
    public static IK9UpdateBuilder AddK9Update(this IServiceCollection services, Action<UpdaterOptions> configure)
    {
        var builder = new K9UpdateBuilder(services);

        services.Configure(configure)
            .PostConfigure<UpdaterOptions>(o => o.Valiate());

        services.AddSingleton<IUpdateManager, DefaultUpdateManager>()
            .AddSingleton<IUpdateClient, DefaultUpdateClient>()
            .AddSingleton<IUpdatePipeManger, UpdatePipeManger>()
            ;

        return builder;
    }
}